package co.uk.j_wp.games.topdowngame;

public class Screen {

	public int[] pixles;
	private int[] colors = new int[256];
	public Screen(int[] pixles){
		this.pixles = pixles;
		
		int pp = 0;
		for (int r = 0; r < 6; r++) {
			for (int g = 0; g < 6; g++) {
				for (int b = 0; b < 6; b++) {
					int rr = (r * 255 / 5);
					int gg = (g * 255 / 5);
					int bb = (b * 255 / 5);
					int mid = (rr * 30 + gg * 59 + bb * 11) / 100;

					int r1 = ((rr + mid * 1) / 2) * 230 / 255 + 10;
					int g1 = ((gg + mid * 1) / 2) * 230 / 255 + 10;
					int b1 = ((bb + mid * 1) / 2) * 230 / 255 + 10;
					colors [pp++] = r1 << 16 | g1 << 8 | b1;
				}
			}
		}
	}
	
	public void setPixel(int x, int y, int i) {
		setPixel(x, y, i, true);
	}

	public void setPixels(int width, int height, int xo, int yo, int[] colors) {
		setPixels(width,height,xo,yo,colors,true);
	}

	public void setPixels(int width, int height, int xo, int yo, int color) {
		for (int y = yo; y < yo + height; y++) {
			for (int x = xo; x < xo + width; x++) {
				setPixel(x, y, color);
			}
		}
	}
	public void clearScreen(){
		setPixels(Game.SCREEN_OVERALL_WIDTH, Game.SCREEN_OVERALL_HEIGHT, 0, 0, 0);
	}

	public void setPixels(int width, int height, int xo, int yo, int[] colors2, boolean b) {
		int pp = 0;
		for (int y = yo; y < yo + height; y++) {
			for (int x = xo; x < xo + width; x++) {
				setPixel(x, y, colors2[pp++],b);
			}
		}
	}

	private void setPixel(int x, int y, int i, boolean b) {
		if (x > -1 && x < Game.SCREEN_OVERALL_WIDTH && y > -1 && y < Game.SCREEN_OVERALL_HEIGHT)
			pixles[Game.SCREEN_OVERALL_WIDTH * y + x] = b?colors[i]:i;
	}
}
